package com.csii.activiti.server.core.entity.db;


import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.annotation.TableName;
import com.csii.activiti.server.core.entity.ActFlowConfiguration;
import com.csii.activiti.server.core.entity.BaseIdAndJsonData;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Date;
import java.util.List;

@Data
@TableName("act_e_flow_configuration")
@NoArgsConstructor
public class ActFlowConfigurationEntity extends BaseIdAndJsonData {

    private String flowName;

    private String flowKey;

    private String description;

    private String status;

    private String groupId;

    private Integer sort;

    private String iconType;

    private Boolean publish;

    private Date lastUpdateTime;

    private String lastUpdateUsername;

    private String pattern;

    private String lastDeploymentId;

    private String flowColumnJson;

    private String flowSignKey;

    private String summary;

    private String resubmitRule;

    private String actTenantId;



    public ActFlowConfigurationEntity(ActFlowConfiguration flow){
        this.setId(flow.getId());
        this.flowName = flow.getFlowName();
        this.flowKey = flow.getFlowKey();
        this.description = flow.getDescription();
        this.status = flow.getStatus();
        this.groupId = flow.getGroupId();
        this.sort = flow.getSort();
        this.iconType = flow.getIconType();
        this.publish = flow.getPublish();
        this.lastUpdateTime = flow.getLastUpdateTime();
        this.lastUpdateUsername = flow.getLastUpdateUsername();
        this.pattern = flow.getPattern();
        this.setJsonData(JSONObject.toJSONString(flow));
        this.flowColumnJson = flow.getFlowColumnJson();
        this.flowSignKey = flow.getFlowSignKey();
        this.summary = flow.getSummary();
        this.resubmitRule = flow.getResubmitRule();
    }


    public ActFlowConfiguration toActFlowConfiguration(){
        ActFlowConfiguration actFlowConfiguration = JSONObject.parseObject(this.getJsonData(), ActFlowConfiguration.class);
        actFlowConfiguration.setGroupId(this.groupId);
        actFlowConfiguration.setFlowColumnJson(this.flowColumnJson);
        return actFlowConfiguration;
    }

    public List<ActCommonDataEntity> toColumnData(){
        if (this.getFlowColumnJson() == null){
            return null;
        }
        return JSONObject.parseArray(this.getFlowColumnJson(),ActCommonDataEntity.class);
    }

}
